/*
   Copyright 2008, Andres Postiglioni

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package com.aconcagua.mvc.factory {
  import com.aconcagua.beans.BeanDefinition;
  import com.aconcagua.beans.BeanDefinitionSupport;
  import com.aconcagua.mvc.factory.support.GestureHandler;

  /**
   * @author Andres Postiglioni
   */
  public class Mediator extends GestureHandler {
    private var _mappings: Array;

    public function Mediator() {
      super(createDefinition);
    }

    private function createDefinition(id: String, metadata: Array): BeanDefinition {
      var definition: BeanDefinitionSupport = new BeanDefinitionSupport(type, id);
      definition.scope = BeanDefinitionSupport.SCOPE_SINGLETON;
      definition.lazy = lazy;
      definition.metadata = metadata;

      return definition;
    }

    /**
     * param theMappings array of GestureMapping
     */
    public function set mappings(theMappings: Array): void {
      _mappings = theMappings;
    }

    /**
     * @param mappings array of GestureMapping
     */
    internal function collectMappings(mappings: Array): void {
      for each (var mapping: GestureMapping in _mappings) {
        mapping.handler = this;
        mappings.push(mapping);
      }
    }
  }
}